package working.complateDemo;


import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
import java.util.stream.IntStream;

public class ComplateTest {


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Executor executor = new ThreadPoolExecutor(100, 500, 10000, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10000));

        long start = System.currentTimeMillis();
        CompletableFuture[] completableFuture = new CompletableFuture[20];
        IntStream.rangeClosed(0, 19).forEach(e -> {
            completableFuture[e] = CompletableFuture.supplyAsync(() -> {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException interruptedException) {
                    interruptedException.printStackTrace();
                }
                return "xxx";
//            }, Executors.newSingleThreadExecutor());
//            }, executor);
            });
        });

        CompletableFuture<Void> voidCompletableFuture = CompletableFuture.allOf(completableFuture);

        voidCompletableFuture.get();
        long end = System.currentTimeMillis();

        System.out.println(end - start);

    }

}
